package com.sheep.opt;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static javax.servlet.http.HttpServletResponse.SC_MOVED_PERMANENTLY;

/**
 * Created by IntelliJ IDEA.
 * User: wnj
 * Date: 2010-11-15
 * Time: 10:30:40
 * To change this template use File | Settings | File Templates.
 */
public class Redirect301 extends org.apache.struts2.dispatcher.ServletRedirectResult{
    public Redirect301() {
        super();
        super.setStatusCode(SC_MOVED_PERMANENTLY);
    }

    public Redirect301(String location) {
        super(location);
        super.setStatusCode(SC_MOVED_PERMANENTLY);
    }

    @Override
    protected void sendRedirect(HttpServletResponse response, String finalLocation) throws IOException {
        response.setHeader("Location",finalLocation);
        response.sendError(SC_MOVED_PERMANENTLY,"Moved Permanently");
//        if (SC_FOUND == statusCode) {
//            response.sendRedirect(finalLocation);
//        } else {
//            response.setStatus(statusCode);
//            response.setHeader("Location", finalLocation);
//            response.getWriter().write(finalLocation);
//            response.getWriter().close();
//        }
    }
}
